/*
 * Copyright (C) 2012 Damien Girard <dgirard@nativesoft.fr>
 * Copyright (C) 2012 Sebastien Baudrand <sebbaudrand@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package fr.umlv.qroxy.communication.transfer;

import fr.umlv.qroxy.http.HttpException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * HTTP data transfer methods.
 * 
 * The idea behind this class is to transfer all datas from one channel
 * to another.
 * 
 * @author Damien Girard <dgirard@nativesoft.fr>
 * @author Sebastien Baudrand <sebbaudrand@gmail.com>
 */
public interface Transfer {
    
    /**
     * Reads data.
     * 
     * @param channel Channel where to read data.
     * @param buffer Buffer where to append new read data.
     * @param useOnlyBuffer Do not read from the channel and use only data
     * contained in the buffer.
     * 
     * @return Number of bytes read and status if read data can be sent.
     */
    TransferResult read(SocketChannel channel, ByteBuffer buffer, boolean useOnlyBuffer) throws IOException, HttpException;
    
    /**
     * Writes data.
     * 
     * @param channel Channel where to write data.
     * @param buffer Buffer where to read data to write.
     * @param limit Limit the amount of data to write.
     * 
     * @return Number of bytes read and status if all datas were written.
     */
    TransferResult write(SocketChannel channel, ByteBuffer buffer, int limit) throws IOException;
    
}
